package com.ruoyi.department.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.department.domain.DepartmentManage;
import com.ruoyi.department.service.IDepartmentManageService;
import com.ruoyi.entity.vo.DepartmentAddVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 部门管理Controller
 * 
 * @author ruoyi
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/departmentManage/departmentManage")
public class DepartmentManageController extends BaseController
{
    @Autowired
    private IDepartmentManageService t05Service;

    /**
     * 查询部门管理列表
     */
    @PreAuthorize("@ss.hasPermi('departmentManage:departmentManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(DepartmentManage t05)
    {
        startPage();
        List<DepartmentManage> list = t05Service.selectDepartmentManageList(t05);
        return getDataTable(list);
    }

    /**
     * 导出部门管理列表
     */
    @PreAuthorize("@ss.hasPermi('departmentManage:departmentManage:export')")
    @Log(title = "部门管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DepartmentManage t05)
    {
        List<DepartmentManage> list = t05Service.selectDepartmentManageList(t05);
        ExcelUtil<DepartmentManage> util = new ExcelUtil<DepartmentManage>(DepartmentManage.class);
        util.exportExcel(response, list, "部门管理数据");
    }

    /**
     * 获取部门管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('departmentManage:departmentManage:query')")
    @GetMapping(value = "/{F0501}")
    public AjaxResult getInfo(@PathVariable("F0501") Long F0501)
    {
        return success(t05Service.selectDepartmentManageByF0501(F0501));
    }

    /**
     * 新增部门管理
     */
    @PreAuthorize("@ss.hasPermi('departmentManage:departmentManage:add')")
    @Log(title = "部门管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(DepartmentAddVo vo,HttpServletRequest request)
    {
        DepartmentManage t05 = new DepartmentManage();
        BeanUtils.copyProperties(vo,t05);
        return toAjax(t05Service.insertDepartmentManage(t05));
    }

    /**
     * 修改部门管理
     */
    @PreAuthorize("@ss.hasPermi('departmentManage:departmentManage:edit')")
    @Log(title = "部门管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DepartmentManage t05)
    {
        return toAjax(t05Service.updateDepartmentManage(t05));
    }

    /**
     * 删除部门管理
     */
    @PreAuthorize("@ss.hasPermi('departmentManage:departmentManage:remove')")
    @Log(title = "部门管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{F0501s}")
    public AjaxResult remove(@PathVariable Long[] F0501s)
    {
        System.out.println(Arrays.toString(F0501s));
        return toAjax(t05Service.deleteDepartmentManageByF0501s(F0501s));
    }
}
